import { ID } from '@/types'
import { request } from '@/utils/request'

export function getAllCategory () {
  return request.get('/boss/resource/category/getAll')
}

export function createOrEditCategory (item: object) {
  return request.post('/boss/resource/category/saveOrderUpdate', item)
}
export function removeCategory (id: ID) {
  return request.delete(`/boss/resource/category/${id}`)
}
export function getCategory (id: ID) {
  return getAllCategory().then(result => {
    if (result.data.code === '000000') {
      id = parseInt(id + '', 10)
      result.data.data = (result.data.data as { id: ID }[]).find(item => item.id === id)
    }
    return result
  })
}

export function createOrEdit (item: object) {
  return request.post('/boss/resource/category/saveOrderUpdate', item)
}
export function removeItem (id: ID) {
  return request.delete(`/boss/resource/${id}`)
}
export function getAll () {
  return request.get('/boss/resource/getAll')
}
// "name": "",
// "startCreateTime": "",
// "url": "",
// "categoryId": 0,
// "endCreateTime": "",
// "current": 0,
// "size": 0
export function getResourcePages (filter: object) {
  return request.post('/boss/resource/getResourcePages', filter)
}
export function getResource (id: ID) {
  return request.get(`/boss/resource/${id}`)
}
